package com.liushao.controller;


import com.liushao.entity.TransFlow;
import com.liushao.result.Result;
import com.liushao.service.TransFlowService;
import com.liushao.util.JwtUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 交易流水表 前端控制器
 * </p>
 *
 * @author chen
 * @since 2025-01-03
 */
@RestController
@RequestMapping("/api/core/transFlow")
public class TransFlowController {

    @Autowired
    private TransFlowService transFlowService;

    /*

        this.$axios.$get('/api/core/transFlow/list').then((response) => {
        this.transFlowList = response.data.list.xxx
     */
 @ApiOperation("获取资金记录列表")
    @GetMapping("/list")
    public Result list(HttpServletRequest request){
     
        String token = null;
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies){
            if(cookie.getName().equals("token")){
                token = cookie.getValue();
                break;
            }
        }     Long userId = JwtUtils.getUserId(token);

    List<TransFlow> transFlowList= transFlowService.selectByUerId(userId);

     return Result.ok().data("list",transFlowList);

 }

}

